When the inference engine needs to discover a fact, it will look for a card having the same name as that fact and, if it finds one, it will display that card and wait to be restarted. If it does not find a card having the same name as the fact or if the fact is not asserted when the inference engine is restarted, it will look for a handler with the same name as the fact. When the inference engine summons a card it stops and you must continue the inference process via the "chain" XCMD. Handlers behave like subroutines. Do not restart the inference engine when the inference engine invokes a handler. The inference engine will automatically continue at the conclusion of the handler.
NOTE: Facts that will use handlers must be named with simple strings. That is,
these fact names must not include white space or special characters, and
they must not match keywords.
You can change the values of facts when they have been previously asserted. However, the inference engine will not re-examine or retract rules or their clauses that have already been processed.
You can retract a fact by assigning it a null value as follows:
PUTINTOFACT "", fact_id -- in HyperTalk
PUT "" INTO FACT fact_id -- in the rule base
Note that even though the system considers the fact "not asserted" when it is assigned a null value, the system will still process any daemons using that fact.
The response of the system to facts being retracted depends on whether it is forward or backward chaining. The sections on forward and backward chaining document the responses for each case.
You may force a match by using the wildcard (*) operand. The wildcard operand will match anything except a fact that is not asserted. You may assign the wildcard operator to a fact via one of the following constructs:
PUTINTOFACT "*", fact_id -- in HyperTalk
PUT "*" INTO FACT fact_id -- in the rule base
When the fact is compared to anything except a fact that is not asserted, it will evaluate true. If it is compared to a fact that is not asserted, the system will cease evaluation of the rule if forward chaining or it will attempt to assert the fact if backward chaining, unless the immediate operator(#) is applied to the fact that is not asserted.
The following example illustrates the use of the wildcard operand.
put * into fact a
if
fact a = 123
then
put 1 into fact b
In the above example, if you backward chain with a goal of "b", the rule will fire, setting fact "b" to 1. When fact "a" is compared to anything except a fact that is not asserted, it will evaluate true.
Similarly, if you compare a fact to a wildcard, it will always evaluate true if it is asserted. For example, assume the rule base contains the following:
put 123 into fact a
if
fact a = *
then
put 1 into fact b
If fact "a" was not asserted, the system would either attempt to assert fact "a" (if backward chaining with a goal of "b") or it would simply cease evaluation of the rule (if forward chaining). Since fact "a" was asserted, the system considers the clause true regardless of the value of fact "a".
The immediate operator will force the inference engine to evaluate a fact at its current value. The inference engine will not attempt to assert the fact and will not cease processing the rule or daemon. If the fact is not asserted, the inference engine will use the null string ("") as its value. The following example illustrates the use of the immediate operator:
fact c
rule "a null"
if
fact c = 1 and
#fact a = "" -- if fact "a" is not asserted
then
put "" into fact b
rule "a asserted"
if
fact c = 1 and
#fact a <> "" -- if fact "a" is asserted
then
put "" into fact b
When forward chaining, if fact "c" were set to 1, the rule "a null" would fire. The system would then examine rule "a asserted" which would prove false because fact "a" is not asserted.
When backward chaining (with a goal of "b"), if fact "c" were set to 1, the rule "a null" would fire. The system would then examine rule "a asserted" which would prove false because fact "a" is not asserted.
The immediate operator has no effect when facts are already asserted, as the system would not have attempted to assert them anyway.